package com.oa.controller.user;

import com.oa.pojo.OaApproval;
import com.oa.service.user.OAService;
import com.oa.vo.PageResult;
import com.oa.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user")
@CrossOrigin
public class OAController {
    @Autowired
    private OAService oaService;

    /**
     * 查询所有OA信息,测试
     * @return
     */
    @GetMapping("/getAllOA")
    public SysResult getAllOA(){

        return SysResult.success(oaService.getAllOA());
    }
    @GetMapping("/list")
    public SysResult getOAList(PageResult pageResult){
        return SysResult.success(oaService.getOAList(pageResult));
    }

    /**
     * 已废弃
     * 查询用户自己提交的OA申请
     * @param id 取浏览器中保存的用户id,通过submitter_id查询
     * @return
     */
    @GetMapping("/getLeaveOAByUser/{id}")
    public SysResult getLeaveOAByUser(@PathVariable Integer id) {
        return SysResult.success(oaService.getOAByUsers(id));
    }
    /**
     * 提交oa申请
     * @param oaApproval
     * @return
     */
    @PostMapping("/submitOA")
    public SysResult submitOA(@RequestBody OaApproval oaApproval){
        oaService.submitOA(oaApproval);
        return SysResult.success();
    }

    /**
     * 用户修改OA时通过id查询
     * @param OAId
     * @return
     */
    @GetMapping("/getOaById/{OAId}")
    public SysResult getOaById(@PathVariable Integer OAId){
        return SysResult.success(oaService.getOaById(OAId));
    }

    /**
     * OA更新
     * @param oaApproval
     * @return
     */
    @PutMapping("/updateOA")
    public SysResult updateOA(@RequestBody OaApproval oaApproval){
        oaService.updateOA(oaApproval);
        return SysResult.success();
    }
    @DeleteMapping("/deleteOA/{oaId}")
    public SysResult deleteOA(@PathVariable Integer oaId){
        oaService.deleteOA(oaId);
        return SysResult.success();
    }

    /**
     * OA审核者查看OA申请
     * @param adminId 审核者id
     * @return
     */
    @GetMapping("/getOAByAdmin/{adminId}")
    public SysResult getOAByAdmin(@PathVariable Integer adminId){
        return SysResult.success(oaService.getOAByAdmin(adminId));
    }
    @PutMapping("/ApproveOA")
    public SysResult ApproveOA(@RequestBody OaApproval oaApproval){
        oaService.ApproveOA(oaApproval);
        return  SysResult.success();
    }

}
